//
//  ST_AIMycenterViewController.swift
//  btvideo
//
//  Created by mac on 2020/3/13.
//  Copyright © 2020 JarvanZhang. All rights reserved.
//

import UIKit
import SwifterSwift
import SwiftyJSON
import SwiftyUserDefaults
import MJRefresh
import RxCocoa
import RxSwift

var ownPeculiarityCount = 0{
    didSet{
        
        NotificationCenter.default.post(name: Notification.Name.peculiarity_count_updated, object: nil)
    }
}

/**
 个人中心 接入百度 识别
 */
class ST_AIMycenterViewController: UIViewController{
    
    static let shared = ST_AIMycenterViewController()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
         
        
        view.addSubview(collectionView)
        collectionView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        
        view.addSubview(edit_btn)
        edit_btn.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(-15+7)
            make.top.equalToSuperview().offset(statusBarHeight+7-7)
            make.width.height.equalTo(44)
        }
        
        view.addSubview(setting_btn)
        setting_btn.snp.makeConstraints { (make) in
            make.right.equalTo(edit_btn.snp.left).offset(-7)
            make.centerY.equalTo(edit_btn)
            make.width.height.equalTo(44)
        }
        
        /*
         view.addSubview(balance_btn)
         balance_btn.snp.makeConstraints { (make) in
         make.left.equalToSuperview().offset(15)
         make.centerY.equalTo(edit_btn)
         make.height.equalTo(28)
         }
         
         view.addSubview(gift_btn)
         gift_btn.snp.makeConstraints { (make) in
         make.left.equalTo(balance_btn.snp.right).offset(15)
         make.centerY.equalTo(edit_btn)
         make.width.height.equalTo(30)
         }*/
        #if DEBUG
                collectionView.mj_header = MJRefreshNormalHeader.init(refreshingBlock: {[weak self] in
                    self?.request_data()
                    
                    self?.collectionView.mj_header?.endRefreshing()
                })
        #endif
        
        
        binding()
    }
    
    func binding(){
        
        
        
        let notifications = [Notification.Name.push_peculiarity_success,Notification.Name.my_pairs_user_info_updated,Notification.Name.like_peculiarity,Notification.Name.approved_peculiarity,Notification.Name.thumbUp,Notification.Name.sort_my_peculiarity,Notification.Name.approved_avatar,NSNotification.Name.my_avatar_updated,Notification.Name.nick_name_audit_failure,Notification.Name.receiveGuard].map({ NotificationCenter.default.rx.notification($0) })
        
        ///合并刷新 信号
        Observable.merge(Observable.merge(notifications).map{ $0 as AnyObject },Observable<Int>.timer(RxTimeInterval.seconds(2*60), scheduler: MainScheduler.instance).map{ $0 as AnyObject }).observe(on: MainScheduler.instance).withUnretained(self).subscribe(onNext: { own , _ in
            
            print("合并📶")
            
            own.request_data()
            
        }).disposed(by: disposeBag)
        
        
        NotificationCenter.default.rx.notification(Notification.Name.modifyIncomeCoin).withUnretained(self).subscribe(onNext: { own,_  in
            
            own.refresh_income_value()
            
        }).disposed(by: disposeBag)
        
        NotificationCenter.default.rx.notification(Notification.Name.modifyCoin).withUnretained(self).subscribe(onNext: { own , _ in
            
            own.update_coin_data()
            
        }).disposed(by: disposeBag)
        
        NotificationCenter.default.rx.notification(Notification.Name.in_pur_status_success).withUnretained(self).subscribe(onNext: {own, _  in
            
            own.member_status_observer()
            
        }).disposed(by: disposeBag)
        
        NotificationCenter.default.rx.notification(Notification.Name.DelDaily).withUnretained(self).subscribe(onNext: {own,notification  in
            
            own.del_daily_noti_handle(noti: notification)
            
        }).disposed(by: disposeBag)
        
       
        
        
        TIANSession(requestUrl: PH.btBaseDataContentApi).subscribe(onNext: { result in
            
            switch result {
            case .success(let json):
                
                DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
                    if let upgradeText = json["data"]["version"]["msg"].string{
                        ST_BTUpgradeController.upgradeNotification(text: upgradeText)
                    }
                }
            case .failure(let err):
                
                print("推荐更新错误❌:",err.e)
                break
            }
        }).disposed(by: disposeBag)
        
        SCComponets.login_status_did_changed_observable().distinctUntilChanged().withUnretained(self).subscribe(onNext: { own,f in
            print("SCComponets.login_status_did_changed_observable()")
            if f == true{
                own.request_data()
            }else{
                own.clear_data()
            }
            own.layout_challenge_view()
            
        }).disposed(by: rx.disposeBag)
        
        
        
        ST_NetworkStatusManager.shared.networkStatusObservable.subscribe(onNext: { state in
            
            if self.headerJson.type == .null && state == .reachable{
                
                self.request_data()
            }
            
        }).disposed(by: rx.disposeBag)
        
        Observable.combineLatest(SCComponets.rich_text_storage_component.pulled_observable, Defaults.rx.observe(Bool.self, DefaultsKeys.isPanda._key)).subscribe { _ in
            
            self.layout_challenge_view()
            
        }.disposed(by: rx.disposeBag)

        
        
    }
    
    func layout_challenge_view(){
        
        
        if Defaults[.isPanda] || SCComponets.rich_text_storage_component.json["ai_my_center"]["challenge_icon"].stringValue.count < 1 {
            
            challenge_btn.isHidden = true
            
            return
        }
        
        
        
        
        //女性
        guard let user = ST_BTUserInfoManager.shared.current_account_info?.userinfo , user.sex == .female else {
            
            challenge_btn.isHidden = true
            
            return
        }
        
        if challenge_btn.superview == nil{
            
            self.view.addSubview(challenge_btn)
            
            challenge_btn.snp.makeConstraints { (make) in
                make.size.equalTo(CGSize.init(width: 72, height: 72))
                make.top.equalToSuperview().offset(140-statusBarHeight+44)
                make.right.equalToSuperview()
            }
        }
        
        
        challenge_btn.pin_setImage(from: SCComponets.rich_text_storage_component.json["ai_my_center"]["challenge_icon"].url)
        
        challenge_btn.isHidden = false
        
        
    }
    
    @objc fileprivate func del_daily_noti_handle(noti:Notification){
        
        let json = JSON(noti.userInfo ?? "")
        
        let id  = json["id"].stringValue
        
        let first = self.pushed_daily_array.removeFirst { (hModel) -> Bool in
            return hModel.id.string  == id
        }
        
        if first != nil , displayTabIndex == 1{
            self.collectionView.reloadData()
        }
    }
    
    
    
    func setUpFeedbackView(){
        
        
        self.view.addSubview(feedback_btn)
        feedback_btn.snp.makeConstraints { (make) in
            make.size.equalTo(CGSize.init(width: 92, height: 80))
            make.top.equalToSuperview().offset(182-statusBarHeight+44)
            make.right.equalToSuperview()
        }
        
        self.view.addSubview(close_feed_back_btn)
        close_feed_back_btn.snp.makeConstraints { (make) in
            make.size.equalTo(CGSize.init(width: 20, height: 20))
            make.bottom.equalTo(feedback_btn.snp.top).offset(2)
            make.right.equalTo(feedback_btn).offset(-10)
        }
        
    }
    @objc fileprivate func relayout_segment_btns(){
        _displayTabIndex = nil
        collectionView.reloadData()
    }
    
    //     MARK: - Properties
    var disposeBag = DisposeBag()
    
    fileprivate var _displayTabIndex:Int?
    fileprivate var displayTabIndex:Int{
        if let idx = _displayTabIndex{
            return idx
        }else{
                _displayTabIndex = 0
                return 0
        }
    }
    
    
    
    fileprivate lazy var ownST_PeculiarityCellSize:CGSize = {
        
        let w = ScreenWidth - 15*2
        
        let h = 200 + 73 - 15
        
        return CGSize.init(width: w, height: h.cgFloat)
    }()
    
    fileprivate lazy var own_peculiarity_no_remark_cell_size:CGSize = {
        
        let w = ScreenWidth - 15*2
        
        let h = 200 + 73 - 15 - 20
        
        return CGSize.init(width: w, height: h.cgFloat)
    }()
    
    fileprivate lazy var headerReferenceSize = CGSize.init(width: ScreenWidth, height: ST_AIMycenterLayout.height)
    
    fileprivate lazy var layout:ST_AIMycenterLayout = {
        let controlLayout = ST_AIMycenterLayout()
        controlLayout.minimumLineSpacing = 15
        controlLayout.minimumInteritemSpacing = 15
        controlLayout.sectionInset = UIEdgeInsets.init(top: 15, left: 15, bottom: BTSafeAreaBottom + 49 + 10, right: 15)
        return controlLayout
    }()
    
    fileprivate lazy var collectionView:UICollectionView = {
        let control = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: self.layout)
        control.delegate = self
        control.dataSource = self
        //        喜欢特质
        control.register(cellWithClass: ST_DAIPeculiarityCell.self)
        //        发布的日常
        control.register(cellWithClass: ST_AICenterDailyCell.self)
        
        control.register(cellWithClass: ST_AICenterAppendDailyCell.self)
        
        control.register(cellWithClass: ST_AICenterAppendST_PeculiarityCell.self)
        
        //        喜欢的人
        control.register(cellWithClass: ST_AIUserCell.self)
        //        拥有特质
        control.register(cellWithClass: ST_AICenterPeculiaritySingleDetailCell.self)
        control.register(cellWithClass: ST_AICenterPeculiarityDoubleDetailCell.self)
        control.register(cellWithClass: ST_AICenterPeculiarityThreeDetailCell.self)
        control.register(cellWithClass: ST_AICenterPeculiarityQuartDetailCell.self)
        
        //        收藏的特质
        control.register(cellWithClass: ST_AIMycenterLovedQuartST_PeculiarityCell.self)
        control.register(cellWithClass: ST_AIMycenterLovedThreeST_PeculiarityCell.self)
        control.register(cellWithClass: ST_AIMycenterLovedDoubleST_PeculiarityCell.self)
        control.register(cellWithClass: ST_AIMycenterLovedSingleST_PeculiarityCell.self)
        
        
        //        空视图
        control.register(cellWithClass: ST_AICenterPeculiarityEmptyCell.self)
        control.register(cellWithClass: ST_AICenterLovedEmptyCell.self)
        
        control.register(cellWithClass: ST_AICenterDailyEmptyCell.self)
        
        
        //        会员
        control.register(cellWithClass: ST_AICenterMemberCell.self)
        control.register(cellWithClass: ST_AICenterFaceStatusCell.self)
        
        //    贵族
        control.register(cellWithClass: ST_AICenterKnighthoodCell.self)
        
        //        header
        control.register(supplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withClass: ST_AIMycenterHeaderView.self)
        if #available(iOS 11.0, *) {
            control.contentInsetAdjustmentBehavior = .never
        }
        control.backgroundColor = Color.white
        
        control.alwaysBounceVertical = true
        
        control.contentInset = UIEdgeInsets.init(top: statusBarHeight - 20, left: 0, bottom: 0, right: 0)
        control.showsVerticalScrollIndicator = false
        control.showsHorizontalScrollIndicator = false
        return control
    }()
    
    fileprivate lazy var edit_btn:UIButton = {
        
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        control.setImageForAllStates(ST_ImageUtils.imageName("个人中心_icon_编辑资料")!)
        control.addTarget(self, action: #selector(push_edit_controller), for: UIControl.Event.touchUpInside)
        return control
    }()
    
    fileprivate lazy var add_photo_btn:UIButton = {
        
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        control.setImageForAllStates(ST_ImageUtils.imageName("个人中心_icon_添加-1")!)
        control.addTarget(self, action: #selector(add_peculiarity_handle), for: UIControl.Event.touchUpInside)
        return control
    }()
    
    fileprivate lazy var setting_btn:UIButton = {
        
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        control.setImageForAllStates(ST_ImageUtils.imageName("个人中心_icon_设置")!)
        control.addTarget(self, action: #selector(push_setting_controller), for: UIControl.Event.touchUpInside)
        return control
    }()
    
    
    fileprivate lazy var balance_btn:ST_CoinButton = {
        
        let control = ST_CoinButton()
        control.addTarget(self, action: #selector(push_coin_controller), for: UIControl.Event.touchUpInside)
        return control
    }()
    
    fileprivate lazy var gift_btn:UIButton = {
        
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        control.setImageForAllStates(ST_ImageUtils.imageName("个人中心_sweet_level_icon")!)
        control.addTarget(self, action: #selector(push_gift_controller), for: UIControl.Event.touchUpInside)
        return control
    }()
    
    fileprivate lazy var feedback_btn:UIButton = {
        
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        control.setImageForAllStates(ST_ImageUtils.imageName("反馈_icon")!)
        control.addTarget(self, action: #selector(push_feed_back_controller), for: UIControl.Event.touchUpInside)
        
        return control
    }()
    
    
    fileprivate lazy var challenge_btn:UIButton = {
        
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        
        control.isHidden = true
        
        control.addTarget(self, action: #selector(push_challenge_controller), for: UIControl.Event.touchUpInside)
        
        return control
    }()
    
    fileprivate lazy var close_feed_back_btn:UIButton = {
        
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        control.setImageForAllStates(ST_ImageUtils.imageName("特质_icon_关闭")!)
        control.addTarget(self, action: #selector(close_feed_back_handle), for: UIControl.Event.touchUpInside)
        return control
    }()
    
    
    
    
    fileprivate var member_cell:ST_AICenterMemberCell?
    
    
    fileprivate var ai_header_view:ST_AIMycenterHeaderView?
    
    fileprivate var headerJson = JSON.null
    
    
    fileprivate var knighthood_json = JSON.null
    /**
     我关注的特质
     */
    //    fileprivate var followedPeculiarityArray = [ST_AIMycenterLovedST_PeculiarityCellModel]()
    
    /**
     我发布的日常
     */
    fileprivate var pushed_daily_array = [DailyMomentOfHallModel]()
    
    
    /*
     第二页开始是调用 单独接口
     **/
    fileprivate var loved_current_page = 1
    
    
    fileprivate lazy var my_peculiarity_array:[ST_PairsPeculiarity] = {
        return [ST_PairsEmptyPeculiarity()]
    }()
    
}
//     MARK: - request_data
extension ST_AIMycenterViewController{
    
    
    @objc func push_challenge_controller(){
        
        ST_BTUserInfoManager.shared.judge_account_frozen().withUnretained(self).subscribe(onNext: { own,_ in
            
            own.navigationController?.pushViewController(ST_TianChallengeController(), animated: true)
            
            
        }).disposed(by: rx.disposeBag)
        
        
    }
    
    @objc fileprivate func network_reachability_status_observer(){
        
        //        if ST_NetworkStatusManager.shared.netStatus == "reachable"
        request_data()
        
    }
    
    
    
    @objc fileprivate func member_status_observer(){
        
        self.member_cell?.refresh_member_status()
        
        self.ai_header_view?.refresh_member_sign()
        
        ST_BTUserInfoManager.shared.pull_additional_attributes()
    }
    
    @objc  func update_coin_data(){
        
        self.ai_header_view?.refresh_little_item_view_value()
    }
    
    @objc  func refresh_income_value(){
        
        self.ai_header_view?.refresh_little_item_view_value()
        
    }
    
    private func clear_data(){
        
        headerJson = JSON.null
        my_peculiarity_array.removeAll()
        
        collectionView.reloadData()
    }
    
    
    @objc  func request_data(){
        
        guard let user = ST_BTUserInfoManager.shared.current_account_info,  user.token.count > 1 else{
            
            clear_data()
            
            return
        }
        
        ST_BTUserInfoManager.shared.pull_additional_attributes()
        
        self.loved_current_page = 1
        
        JVrequest(PH.personalSpaceApi, success: { (json) in
            
            self.layout.headerReferenceSize = self.headerReferenceSize
            
            
            let data = json["data"]
            
            print("百度Ai版本 个人中心数据:",data)
            
            //            if data["is_feedback"].boolValue{
            //                self.setUpFeedbackView()
            //            }
            
            self.headerJson = data["information"]
            
            self.knighthood_json = data["nobility"]
            
            BINP.save_gradient_effect_struct(accid: user.accid, nobleLevel: self.knighthood_json["id"].intValue, nobleUrl: self.knighthood_json["image"].stringValue)
            
            //            .如果用户填写了“个人介绍”，“添加个人介绍”取消不显示
            let personal_desc = self.headerJson["personal_desc"].stringValue
            
            if !personal_desc.isEmpty ||  personal_desc != ""{
                ST_PinterestHomeGuidanceManager.shared.hidden_add_intro()
            }
            
            
            IS_INVISIBLE = self.headerJson["online_mode"].intValue == 2
            
            self.update_coin_data()
            
            ST_BTUserInfoManager.shared.modify_current_account(aiCenterJson: self.headerJson)
            
            Defaults[.BTPeuliarityDataType] = data["data_type"].intValue
            
            
            if let list0 = [ST_PairsPeculiarity].deserialize(from: data["own_feature"].rawString() ?? "") as? [ST_PairsPeculiarity]{
                
                self.my_peculiarity_array = list0
                
                ownPeculiarityCount = list0.count
                //                self.my_peculiarity_array.forEach({ $0.remark = Bool.random() ? "你好" :"" })
                
            }
            //            默认添加空视图
            if self.my_peculiarity_array.count < 1{
                let m = ST_PairsEmptyPeculiarity()
                self.my_peculiarity_array = [m]
            }else{
                self.my_peculiarity_array.insert(ST_PairsAppendPeculiarity(), at: 0)
            }
            
            /*
             if let list1 = [ST_PairsPeculiarity].deserialize(from: data["like_feature"].rawString() ?? "") as? [ST_PairsPeculiarity]{
             self.loveDataArray = list1
             }*/
            
            
            self.collectionView.reloadData()
            
            print("百度AI版-个人中心：",json)
            
            
        }) { (code, err) in
            
            print("百度Ai版本 个人中心数据:",err)
            
            self.collectionView.mj_footer?.endRefreshing()
            
            ToastHud(text: err, view: self.view)
        }
        
        
    }
    
    
}

//     MARK: - Delegate
extension ST_AIMycenterViewController:UICollectionViewDataSource,UICollectionViewDelegateFlowLayout{
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        
        if displayTabIndex == 0 {
            return my_peculiarity_array.count
        }else if displayTabIndex == 1{
            return 1
        }else{
            return 1
        }
    }
    
    func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
        
        let header = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, withClass: ST_AIMycenterHeaderView.self, for: indexPath)
        
        header.json = self.headerJson
        
        header.switch_tab_closure = { [weak self] idx in
            self?._displayTabIndex = idx
            self?.collectionView.reloadData()
        }
        
        header.ask_refresh_closure = { [weak self]  in
            self?.request_data()
        }
        
        self.ai_header_view = header
        
        return header
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
        
        if displayTabIndex == 0 {
            
            let myModel = my_peculiarity_array[indexPath.row]
            
            if myModel is ST_PairsEmptyPeculiarity{
                
                let cell = collectionView.dequeueReusableCell(withClass: ST_AICenterPeculiarityEmptyCell.self, for: indexPath)
                
                return cell
                
            }
            
            if myModel is ST_PairsAppendPeculiarity{
                
                let cell = collectionView.dequeueReusableCell(withClass: ST_AICenterAppendST_PeculiarityCell.self, for: indexPath)
                
                return cell
                
            }
            
            let count = myModel.detail.count
            
            if count >= 4{
                let cell = collectionView.dequeueReusableCell(withClass: ST_AICenterPeculiarityQuartDetailCell.self, for: indexPath)
                cell.model = myModel
                return cell
            }else if count == 3{
                let cell = collectionView.dequeueReusableCell(withClass: ST_AICenterPeculiarityThreeDetailCell.self, for: indexPath)
                cell.model = myModel
                return cell
            }else if count == 2{
                let cell = collectionView.dequeueReusableCell(withClass: ST_AICenterPeculiarityDoubleDetailCell.self, for: indexPath)
                cell.model = myModel
                return cell
            }else{
                let cell = collectionView.dequeueReusableCell(withClass: ST_AICenterPeculiaritySingleDetailCell.self, for: indexPath)
                cell.model = myModel
                return cell
            }
            
        }else if displayTabIndex == 1{
            
            
            let cell = collectionView.dequeueReusableCell(withClass: ST_AICenterKnighthoodCell.self, for: indexPath)
            
            cell.json = knighthood_json
            
            return cell
            
        }
        
        else if displayTabIndex == 2{
            
            let cell = collectionView.dequeueReusableCell(withClass: ST_AICenterFaceStatusCell.self, for: indexPath)
            
            cell.refresh_face_status()
            
            return cell
            
        }
        else{
            
            let cell = collectionView.dequeueReusableCell(withClass: ST_AICenterMemberCell.self, for: indexPath)
            
            cell.refresh_member_status()
            
            
            member_cell = cell
            
            return cell
            
        }
    }
    
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        
        if displayTabIndex == 0 {
            
            if my_peculiarity_array[indexPath.row] is ST_PairsAppendPeculiarity{
                return CGSize.init(width: ScreenWidth - 15*2, height: 80)
            }
            
            if my_peculiarity_array[indexPath.row].remark.isEmpty{
                return own_peculiarity_no_remark_cell_size
            }
            return ownST_PeculiarityCellSize
        }else if displayTabIndex == 1{
            
            return CGSize.init(width: ScreenWidth, height: ST_AICenterKnighthoodCell.height)
            
        }else if displayTabIndex == 2{
            return CGSize.init(width: ScreenWidth-15*2, height: ST_AICenterFaceStatusCell.height)
        }
        else{
            return CGSize.init(width: ScreenWidth-15*2, height: ST_AICenterMemberCell.height)
        }
        
    }
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        
        switch displayTabIndex {
        case 0:
            
            let myModel = my_peculiarity_array[indexPath.row]
            
            if myModel is ST_PairsEmptyPeculiarity || myModel is ST_PairsAppendPeculiarity{
                return
            }
            
            let vc = ST_SinglePeculiarityWaterfallController()
            vc.userID = Defaults[.currentUserID]
            vc.peculiarity_id = my_peculiarity_array[indexPath.row].id.string
            vc.type = .me
            
            navigationController?.pushViewController(vc)
            
        case 1:
            
            navigationController?.pushViewController(ST_KnighthoodLevelController())
            
        default:
            break
        }
        
    }
    
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        
        //
        if scrollView.contentOffset.y > ST_AIMycenterLayout.height - ST_AIMycenterLayout.stickOffset{
            
            UIView.animate(withDuration: 0.25, animations: {
                
                self.setting_btn.alpha = 0
                self.add_photo_btn.alpha = 0
                self.edit_btn.alpha = 0
                self.balance_btn.alpha = 0
                self.gift_btn.alpha = 0
            }) { (f) in
                
            }
            
        }else{
            
            UIView.animate(withDuration: 0.25, animations: {
                
                self.setting_btn.alpha = 1
                self.add_photo_btn.alpha = 1
                self.edit_btn.alpha = 1
                self.balance_btn.alpha = 1
                self.gift_btn.alpha = 1
            }) { (f) in
                
            }
        }
    }
    
}


//     MARK: - Event
extension ST_AIMycenterViewController{
    
    @objc func add_peculiarity_handle(){
        
        
        push_to_push_peculiarity_controller(navigationController: self.navigationController)
    }
    
    @objc func push_edit_controller(){
        
        let editVC = ST_EditMyInfoViewController()
        
        self.navigationController?.pushViewController(editVC, animated: true)
        
    }
    @objc func push_gift_controller(){
        
        self.navigationController?.pushViewController(ST_GiftRankViewController(), animated: true)
        
    }
    
    @objc func push_coin_controller(){
        
        
        self.navigationController?.pushViewController(ST_RechargeViewController(), animated: true)
        
    }
    
    @objc func push_setting_controller(){
        
        self.navigationController?.pushViewController(ST_BTSettingController(), animated: true)
        
    }
    
    @objc func push_feed_back_controller(){
        
        self.navigationController?.pushViewController(ST_FeedBackViewController(), animated: true)
        
    }
    
    
    
    
    @objc func close_feed_back_handle(){
        
        self.feedback_btn.isHidden = true
        
        self.close_feed_back_btn.isHidden = true
        
    }
    
}


class ST_DAIPeculiarityCell: ST_PeculiarityCell {
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        cover_image_view.snp.updateConstraints { (make) in
            make.top.equalToSuperview()
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}





fileprivate class ST_CoinButton:UIControl{
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.cornerRadius = 13
        self.backgroundColor = UIColor.init(hex: 0x1E2022, transparency: 0.3)
        
        self.addSubview(avatar_image_view)
        avatar_image_view.snp.makeConstraints { (make) in
            make.width.height.equalTo(18)
            make.top.left.equalToSuperview().offset(5)
        }
        
        self.addSubview(content_label)
        content_label.snp.makeConstraints { (make) in
            make.left.equalTo(avatar_image_view.snp.right).offset(4)
            make.right.equalToSuperview().offset(-6)
            make.centerY.equalToSuperview()
        }
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //    MARK: - properties
    var value = 0{
        didSet{
            content_label.text = value.string
        }
    }
    
    fileprivate lazy var content_label:UILabel = {
        let control = UILabel.init()
        control.text = "0"
        control.textColor = Color.white
        control.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.bold)
        return control
    }()
    
    fileprivate lazy var avatar_image_view:UIImageView = {
        let control = UIImageView.init(image: ST_ImageUtils.imageName("coin_icon"))
        return control
    }()
}
